package com.inboyu.admin.domain;

import com.inboyu.listing.domain.StoreId;
import lombok.Getter;

import java.time.LocalDateTime;

/**
 * 合同实体类
 * @author linyu
 * @date 2025年8月21日
 */
@Getter
public class ContractEntity {

    /**
     * 合同ID
     */
    private ContractId id;

    /**
     * 合同编号
     */
    private String contractNo;

    /**
     * 门店ID
     */
    private StoreId storeId;

    /**
     * 合同名称
     */
    private String contractName;

    /**
     * 模块标签
     */
    private ModuleTag moduleTag;

    /**
     * 开始租赁（起租）时间
     */
    private LocalDateTime startRentTime;

    /**
     * 在线合同条款
     */
    private String onlineContract;

    /**
     * 支付交费周期
     */
    private Integer paymentCycle;

    /**
     * 交费周期推送方式
     */
    private PushType pushType;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 创建人
     */
    private String createUser;

    /**
     * 修改时间
     */
    private LocalDateTime updateTime;

    /**
     * 修改人
     */
    private String updateUser;

    /**
     * 删除标识；0-正常，1-删除
     */
    private Integer deleted;

    /**
     * 版本号，起势版本为1，每次更新基于上一条版本加1，根据门店Id唯一
     */
    private Integer version;

    /**
     * 合同类型
     */
    private ContractType contractType;

    /**
     * 合同状态
     */
    private ContractStatus contractStatus;

    public ContractEntity(String contractNo, StoreId storeId, String contractName, ModuleTag moduleTag,
                          LocalDateTime startRentTime, String onlineContract, Integer paymentCycle,
                          PushType pushType, ContractType contractType) {
        this.contractNo = contractNo;
        this.storeId = storeId;
        this.contractName = contractName;
        this.moduleTag = moduleTag;
        this.startRentTime = startRentTime;
        this.onlineContract = onlineContract;
        this.paymentCycle = paymentCycle;
        this.pushType = pushType;
        this.createTime = LocalDateTime.now();
        this.createUser = "createUser";
        this.updateTime = LocalDateTime.now();
        this.updateUser = "updateUser";
        this.deleted = 0;
        this.contractType = contractType;
        this.contractStatus = ContractStatus.WAIT_APPROVE;
    }

    public void deleteContract(String updateUser) {
        this.deleted = 1;
        this.updateUser = updateUser;
        this.updateTime = LocalDateTime.now();
    }

    public void createContract(String createUser, int version) {
        this.createUser = createUser;
        this.createTime = LocalDateTime.now();
        this.version = version + 1;
        this.deleted = 0;
    }

}
